﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentNHibernate.Mapping;
using YasharEl.Infrastructure.Core.EntityModel.Prototype;
using YasharEl.Infrastructure.PersistenceModel.NHibernate.UserTypes;
using YasharEl.Infrastructure.Core.Prototype;

namespace YasharEl.Infrastructure.Core.PersistenceModel.NHibernate.Prototype.Mappings
{
    public class AbstractPropertyMappingEntityMap : ClassMap<AbstractPropertyMappingEntity>
    {
        public AbstractPropertyMappingEntityMap()
        {
            Table("PropertyMappings");
            ReadOnly();
            Cache.ReadOnly();

            Id(e => e.PropertyMappingId)
                .Column("PropertyMappingId")
                    .GeneratedBy.Assigned();

            References(e => e.PropertyDefinition)
                .Column("PropertyDefinitionId")
                .Not.Nullable()
                .LazyLoad()
                .Class<PropertyDefinitionEntity>();

            Map(e => e.IsRequired)
                .Column("IsRequired")
                .Not.Nullable();

            Map(e => e.IsEditable)
                .Column("IsEditable")
                .Not.Nullable();

            Map(e => e.IsVisible)
                .Column("IsVisible")
                .Not.Nullable();

            DiscriminateSubClassesOnColumn("PrototypedObjectType")
                .Not.Nullable()
                .AlwaysSelectWithValue();
        }
    }
}
